<?php
/**
 * Created by PhpStorm.
 * User: xi
 * Date: 2020-05-02
 * Time: 16:54
 */

namespace app\api\service;


use app\admin\model\Devices;
use app\admin\model\Dy;
use app\admin\model\Dyhotel;
use app\admin\model\Hotel;
use app\admin\model\litestore\Litestoreorder;
use app\admin\model\litestore\Litestoreordergoods;
use app\admin\model\Monthdevice;
use app\admin\model\Order;
use app\admin\model\Partner;
use app\admin\model\Partnerdevice;
use app\admin\model\Pinprofit;
use app\admin\model\Profitbuy;
use app\admin\model\Profitorder;
use app\admin\model\Profittrade;
use app\admin\model\Profitvip;
use app\admin\model\User;
use app\admin\model\Userrelation;
use app\admin\model\Userwithdraw;
use think\Db;
use think\Exception;

class ProfitService
{




    //用户余额
    public function userProfit($uid)
    {

        $incomeAmount = $this->userIncome($uid);
        $userWithdrawModel = new Userwithdraw();
        $withdraw = $userWithdrawModel->where('uid',$uid)->sum('amount');
        $amount = sprintf("%.2f", ($incomeAmount - $withdraw));
        return $amount;

    }

    //用户收入
    public function userIncome($uid){

        $profitModel = new Profitorder();
        $productAmount = $profitModel->where('uid',$uid)->sum('amount');
        $profitOrderModel = new Profitvip();
        $vipAmount = $profitOrderModel->where('uid',$uid)->sum('amount');

        $profitPinModel = new Pinprofit();
        $pinAmount = $profitPinModel->where('uid',$uid)->sum('amount');


        return  ($productAmount+$vipAmount+$pinAmount);
    }


}